﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OneSystems.Data.Entities;
using OneSystems.BusinessLogic;

namespace UserInterface.HelperForms
{
    public partial class EditDebtor : Form
    {
        public int DebtorID { get; set; }
        public EditDebtor()
        {
            InitializeComponent();
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SaveButton_Click(object sender, EventArgs e)
        {
            DebtorLogic.SaveDebtor(DebtorID, LastnameBox.Text, FirstnameBox.Text, 
                MiddlenameBox.Text, PledeAmountBox.Value, (DateTime)BirthdaySelector.Value);
            this.Close();
        }

        private void EditDebtor_Load(object sender, EventArgs e)
        {
            InitializeDebtor();
        }

        private void InitializeDebtor()
        {
            if (DebtorID > 0)
            {
                Debtor debtor = DebtorLogic.GetUser(DebtorID);
                LastnameBox.Text = debtor.Surname;
                FirstnameBox.Text = debtor.GivenName;
                MiddlenameBox.Text = debtor.OtherNames;
                PledeAmountBox.Value = debtor.PledgeAmount;
                BirthdaySelector.Value = debtor.BirthDate;
            }
        }
    }
}
